package com.example;

import java.time.LocalDate;
import javax.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import com.example.dao.BaseDAO;
import com.example.entity.InterfaceTrafficRecordDay;
import com.example.service.InterfaceTrafficRecordDayService;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class Main {
    @Resource
    private BaseDAO baseDAO;

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); // 修改为正确的配置文件名
        InterfaceTrafficRecordDayService recordDayService = context.getBean(InterfaceTrafficRecordDayService.class);

        InterfaceTrafficRecordDay record = InterfaceTrafficRecordDay.builder()
                .interfaceName("/api/example")
                .requestCount(100)
                .recordType(1) // 使用整数值表示类型
                .recordTime(LocalDate.now())
                .publicId(12341L)
                .clientId("client121")
                .build();

        recordDayService.addInterfaceTrafficRecordDay(record);
        log.info("InterfaceTrafficRecordDay record added successfully: {}", record);

        // 更新数据示例
        InterfaceTrafficRecordDay existingRecord = recordDayService.getInterfaceTrafficRecordDayById(1L); // 假设 ID 为 1
        if (existingRecord != null) {
            existingRecord.setRequestCount(500); // 更新请求次数
            recordDayService.updateInterfaceTrafficRecordDay(existingRecord);
            log.info("InterfaceTrafficRecordDay record updated successfully: {}", existingRecord);
        } else {
            log.warn("No record found with ID 1");
        }
    }
}